USE [iCoffee]
GO

/****** Object:  StoredProcedure [dbo].[usp_LST_Supplier]    Script Date: 05/24/2012 08:55:29 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE Proc [dbo].[usp_LST_Supplier]
	@Command nvarchar(255),
	@SupplierID	INT=NULL OUTPUT,
	@Code	nvarchar(50)=null,
	@Name	nvarchar(200)=null,
	@Address	nvarchar(200) = '',
	@Tel	nvarchar(50) = '',
	@Notes	nvarchar(200) = ''
AS
Begin

	If @Command = 'Update'
	Begin
		If Not Exists(Select SupplierID From LST_Supplier Where SupplierID = @SupplierID )
		Begin
			Insert Into LST_Supplier(Code,Name,Address,Tel,Notes)
			Values(@Code,@Name,@Address,@Tel,@Notes)
			Set @SupplierID = @@identity
		End
		Else
			Update LST_Supplier Set Code = @Code,Name = @Name,Address = @Address,Tel = @Tel,Notes = @Notes
			Where SupplierID = @SupplierID 
	End

	If @Command = 'Delete'
	Begin
		Delete From LST_Supplier
		Where SupplierID = @SupplierID 
	End

	If @Command = 'LoadData'
	Begin
		Select * From LST_Supplier
		Where (@SupplierID IS NULL OR SupplierID = @SupplierID )
	END
	
	If @Command = 'GetAll'
	Begin
		Select * From LST_Supplier
	END
End

GO

